home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: simchoni@netvision.net.il (Uri Simchoni)
- Newsgroups: comp.lang.c
- Subject: State machine design
- Date: 23 Mar 1996 10:09:25 GMT
- Organization: Simchoni Automation Systems Ltd
- Message-ID: <4j0ikl$9t5@news.NetVision.net.il>
- NNTP-Posting-Host: ts006p13.pop4a.netvision.net.il
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- Hi,
-
- I'm designing what I call a communication server. This a program which
- receives messages from the network sends these messages to a device over
- the serial port according to the device's proprietary protocol, and sends
- the device's reply back over the network.
-
- What I have in mind is to split the program into three basic modules. The
- first one handles the RS232 communications, the second handles the
- protocol logic and the third handles network traffic. Due to operating
- system constraints (the OS is DOS and the computer the program runs on
- should do other things), I can't use a model of "wait for a call from the
- network, process that call and send your reply". I have to use some kind
- of a state machine in the protocol logic module. The protocol logic
- module will have functions that get called by the other modules whenever
- an event occurs (clock tick, character arriving from the serial port,
- request from the network, etc.)
-
- After this LONG outline of the problem I get to my question. I'm
- considering several designs for the state machine interface. One is to
- have a distinct function for each type of event. The function decides
- what to do according to module's internal data. Another is to have a
- pointer to the function that handles all events for the current state. If
- the state should change, the pointer is modified. Another design lays
- somewhere in between - to have a sparate function for each type of event
- and each state.
- Since my experience with such program is nearly zero, I cannot tell if
- one design is preferable over the other (or if there's a better way of
- doing these things). I'd appreciate anyone's input on the subject. I
- think the primary issues that should be considered are ease of
- implementation(handling reentrancy problems, etc), debugging, and
- readability. Ease of making changes isn't a major issue since the serial
- protocol is fixed and well established.
-
- Thanks,
-
- Uri Simchoni
- simchoni@netvision.net.il
-
-